<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="insertPoint"></div><br>
    <button id="btn_time">时间停止</button>
</body>
</html>
<script>
    let node=document.getElementById("insertPoint");
    document.getElementById("btn_time").addEventListener("click",()=>{
        let button=document.getElementById("btn_time");
        if(button.innerHTML=="时间停止"){
            clearInterval(timeId);
            button.innerHTML="时间开始";
        }else{
            button.innerHTML="时间停止";
            timeId=setInterval("setDateTime()",1000);
        }

    },false);
    let timeId=0;
    function setDateTime(){
        let date = new Date();
        node.innerHTML="现在时间："
        node.innerHTML+=date.getFullYear()+"年";
        node.innerHTML+=(date.getMonth()+1)+"月";
        node.innerHTML+=date.getDate()+"日 ";
        node.innerHTML+=date.getHours()+"点";
        node.innerHTML+=date.getMinutes()+"分";
        node.innerHTML+=date.getSeconds()+"秒";
    }
    timeId=setInterval("setDateTime()",1000);
</script>